package oj;

import java.util.Scanner;

public class Day19S {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            String s1=sc.nextLine();
            String s2=sc.nextLine();
            if(s1.length()>s2.length()){
                String tmp=s1;
                s1=s2;
                s2=tmp;
            }
            int maxLen=0;
            int maxIndex=0;
            int[][] arr=new int[s1.length()+1][s2.length()+1];
            for (int i = 0; i < s1.length(); i++) {
                arr[i][0]=0;

            }
            for (int i = 0; i < s2.length(); i++) {
                arr[0][i]=0;
            }
            for (int i = 1; i < s1.length(); i++) {
                for (int j = 1; j < s2.length(); j++) {
                    if (s1.charAt(i-1) == s2.charAt(j-1)) {
                        arr[i][j]=arr[i-1][j-1]+1;
                    }
                    if(maxLen<arr[i][j]){
                        maxLen=arr[i][j];
                        maxIndex=i;
                    }
                }
            }
            System.out.println(s1.substring(maxIndex-maxLen,maxIndex));
        }
    }
}
